package com.fjl.boot;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

// 11. ImportBeanDefinitionRegistrar 动态注册 Bean
@Configuration
class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        System.out.println(">> ImportBeanDefinitionRegistrar.registerBeanDefinitions");
        registry.registerBeanDefinition("myImportedBean", BeanDefinitionBuilder.genericBeanDefinition(DynamicBean.class).getBeanDefinition());
    }
}
